
package com.visionet.waveletData.web.entity.business;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.visionet.waveletData.web.common.utilities.MessageSourceHelper;
import com.visionet.waveletData.web.common.utilities.time.DateUtil;
import com.visionet.waveletData.web.common.utils.Validator;
import com.visionet.waveletData.web.entity.IdEntity;
import com.visionet.waveletData.web.entity.JsonDateSerializer;
/**
 * 用户信息
 * @author head-master
 *
 */

@Entity
@Table(name = "s_user_info")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 
public class UserInfo extends IdEntity implements Serializable {
	
	private static final long serialVersionUID = 4608763054831055888L;

	public UserInfo(){  
		
	}
	public UserInfo(Long id){
		this.id = id;
	}
	private String loginName;
	private String signature;
	private String qq;
	private String weixin;
	private Long phoneNumber;
	private Long imageId;
	private Integer gender;
	private Date birthday;		//生日
	private String userName;
	private String trueName;
	private String title;		//职位

	private String email;		//电子邮件
	private String address;		//所在地
	private String website;		//个人网站
	private String firstLetter;
	private String trueFirstLetter;
	private Integer isLock;
	
//	private String imageUrl;
//
//	private Integer streamCount;
//	
//	private Integer imageCount;
	
	private Date createDate;
	private Date updateDate;
    private Date lastLogin;
    private Date deductionDate;

	private Short receiveMessage;
	
	private Long orgId;
	private String orgName;
	
	private Short allowLoginFromMobile;

	private Integer forWeixin;
	
	private Integer blogCount;
	private Integer questionCount;
	
	private Float integral;
    private Float integralBadge;  //版主积分额度
    private Integer badge;          //身份徽章
    private Float integralYesterday;
    private Float integralYesterdayBefore;
    private String integralUpDown;

	private Long departmentId;
	
	private Integer viewPhone; //是否显示手机号码
	private String locale;
    private Integer level;      //1:合理化建议查询权限
    private String backPicUrl;
    private List<String> seedRoles;

    private String chexiangAccount;
    private String chexiangPsw;

	public Integer getViewPhone() {
		return viewPhone;
	}
	public void setViewPhone(Integer viewPhone) {
		this.viewPhone = viewPhone;
	}
	@Transient
	public String getIntimatePhone(){
		if(viewPhone == null || viewPhone == 0){
			return MessageSourceHelper.GetMessages("app.entity.business.UserInfo.onopen");
		}else{
			if(Validator.isNotNull(phoneNumber)){
				return phoneNumber.toString();
			}
			return "";
		}
	}

	public Float getIntegral() {
		return integral;
	}
	public void setIntegral(Float integral) {
		this.integral = integral;
	}

    @Transient
	public String getBirthdayFormat(){
		if(birthday != null){
			return DateUtil.convertToString(birthday, DateUtil.YMD1);
		}
		return null;
	}
	@Transient
	public Integer getBlogCount() {
		return blogCount;
	}
	public void setBlogCount(Integer blogCount) {
		this.blogCount = blogCount;
	}
	@Transient
	public Integer getQuestionCount() {
		return questionCount;
	}
	public void setQuestionCount(Integer questionCount) {
		this.questionCount = questionCount;
	}
	public Integer getForWeixin() {
		return forWeixin;
	}
	public void setForWeixin(Integer forWeixin) {
		this.forWeixin = forWeixin;
	}
	public Short getAllowLoginFromMobile() {
		return allowLoginFromMobile;
	}
	public void setAllowLoginFromMobile(Short allowLoginFromMobile) {
		this.allowLoginFromMobile = allowLoginFromMobile;
	}
	public Short getReceiveMessage() {
		return receiveMessage;
	}
	public void setReceiveMessage(Short receiveMessage) {
		this.receiveMessage = receiveMessage;
	}
	

	public Long getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(Long phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public Long getImageId() {
		return imageId;
	}
	public void setImageId(Long imageId) {
		this.imageId = imageId;
	}
	public Integer getGender() {
		return gender;
	}
	public void setGender(Integer gender) {
		this.gender = gender;
	}
	
	public String getTrueName() {
		return trueName;
	}
	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
	public String getTrueFirstLetter() {
		return trueFirstLetter;
	}
	public void setTrueFirstLetter(String trueFirstLetter) {
		this.trueFirstLetter = trueFirstLetter;
	}
	public String getFirstLetter() {
		return firstLetter;
	}
	public void setFirstLetter(String firstLetter) {
		this.firstLetter = firstLetter;
	}
	
	@Column(insertable=false,updatable=false)
	@JsonSerialize(using = JsonDateSerializer.class)
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public Date getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	@JsonSerialize(using = JsonDateSerializer.class)
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public Integer getIsLock() {
		return isLock;
	}
	public void setIsLock(Integer isLock) {
		this.isLock = isLock;
	}

    @Override
    public int hashCode(){
        return this.getId()==null?1:this.getId().hashCode();
    }
	@Override
	public boolean equals(Object obj) {
		if( null== obj||!( obj instanceof UserInfo)){
			return false;
		}
		UserInfo userInfo = (UserInfo)obj;
		if(userInfo.getId()==null){
			return false;
		}
		return userInfo.getId().equals(this.id);
	}

//	@Formula("(select count(1) from s_stream s where s.create_by= id)")
//	public Integer getStreamCount() {
//		return streamCount;
//	}
//	public void setStreamCount(Integer streamCount) {
//		this.streamCount = streamCount;
//	}
//	@Formula("(select count(1) from s_image si where si.create_id= id)")
//	public Integer getImageCount() {
//		return imageCount;
//	}
//	public void setImageCount(Integer imageCount) {
//		this.imageCount = imageCount;
//	}
//	@Formula("(select i.min_url from s_image i where i.id = image_id)")
//	public String getImageUrl() {
//		return imageUrl;
//	}
//	public void setImageUrl(String imageUrl) {
//		this.imageUrl = imageUrl;
//	}
//
//	@Transient
//	public String getUserImgUrl() {	//用户头像url
//		return UserInfoService.getUserImgUrl(this.id);
//	}
	public String getSignature() {
		return signature;
	}
	public void setSignature(String signature) {
		this.signature = signature;
	}
	public String getQq() {
		return qq;
	}
	public void setQq(String qq) {
		this.qq = qq;
	}
	public Long getOrgId() {
		return orgId;
	}
	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}
	public String getOrgName() {
		return orgName;
	}
	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getWebsite() {
		return website;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
	public Long getDepartmentId() {
		return departmentId;
	}
	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}
	public String getWeixin() {
		return weixin;
	}
	public void setWeixin(String weixin) {
		this.weixin = weixin;
	}
	public String getLocale() {
		return locale;
	}
	public void setLocale(String locale) {
		this.locale = locale;
	}

    public Float getIntegralBadge() {
        return integralBadge;
    }

    public void setIntegralBadge(Float integralBadge) {
        this.integralBadge = integralBadge;
    }

    public Float getIntegralYesterday() {
        return integralYesterday;
    }

    public void setIntegralYesterday(Float integralYesterday) {
        this.integralYesterday = integralYesterday;
    }

    public Float getIntegralYesterdayBefore() {
        return integralYesterdayBefore;
    }

    public void setIntegralYesterdayBefore(Float integralYesterdayBefore) {
        this.integralYesterdayBefore = integralYesterdayBefore;
    }

    public String getIntegralUpDown() {
        return integralUpDown;
    }

    public void setIntegralUpDown(String integralUpDown) {
        this.integralUpDown = integralUpDown;
    }

    public Integer getBadge() {
        return badge;
    }

    public void setBadge(Integer badge) {
        this.badge = badge;
    }
    @Column(name="LEVEL_")
    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getBackPicUrl() {
        return backPicUrl;
    }

    public void setBackPicUrl(String backPicUrl) {
        this.backPicUrl = backPicUrl;
    }

    public String getChexiangAccount() {
        return chexiangAccount;
    }

    public void setChexiangAccount(String chexiangAccount) {
        this.chexiangAccount = chexiangAccount;
    }

    public String getChexiangPsw() {
        return chexiangPsw;
    }

    public void setChexiangPsw(String chexiangPsw) {
        this.chexiangPsw = chexiangPsw;
    }

    @Transient
	public int getAge() {
		return DateUtil.getAge(this.birthday);
	}

    @Column(insertable=false)
    @JsonSerialize(using = JsonDateSerializer.class)
    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    @Transient
    public List<String> getSeedRoles() {
        return seedRoles;
    }

    public void setSeedRoles(List<String> seedRoles) {
        this.seedRoles = seedRoles;
    }

    @JsonIgnore
    public Date getDeductionDate() {
        return deductionDate;
    }

    public void setDeductionDate(Date deductionDate) {
        this.deductionDate = deductionDate;
    }
}
